package freemind.controller;

import javax.swing.tree.TreeNode;

import freemind.controller.ActionResponseListener;
import freemind.controller.CustomController;
import freemind.modes.browsemode.BrowseNodeModel;
import freemind.view.mindmapview.NodeView;

public class OuvinteControllerAction implements ActionResponseListener{

	private BrowseNodeModel lastNode = null;
	private NodeView copiedNode = null;
	private CustomController c;
	
	public void waitSaveToLink(BrowseNodeModel lastNode){
		this.lastNode = lastNode;
	}
	
	public void waitSaveToCopy(NodeView lastNode){
		this.copiedNode = lastNode;
	}	
	
	public OuvinteControllerAction(CustomController c){
		this.c = c;
	}
	
	public void sucessoAoCarregar() {
		// TODO Auto-generated method stub
		
	}

	public void sucessoAoSalvar() {
		// TODO Auto-generated method stub
		
//		System.out.println("LINKANDO AGORA " + lastNode );
		
		if( lastNode!= null ){
			TreeNode parent = (TreeNode) lastNode.getParent();
			lastNode = c.getNodeByIndex(parent, parent.getIndex(lastNode)); /* Atualizar os dados do no */
			c.willLinkNode(lastNode.getViewer());
		}
		
		if( copiedNode!= null ){
			c.copiaNode(copiedNode);
		}
	}
	
}
